﻿layui.use('table', function () {
    var table = layui.table
    table.render({
        elem: '#test'
        , url: '/FileList/Show'
        , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        , cols: [[
            { field: 'FileName', width: 100, title: '文件名字', }
            , { field: 'FileType', width: 100, title: '文件类型' }
            , { field: 'UploadTime', templet: "<div>{{Format(d.UploadTime,'yyyy-MM-dd')}}</div>", width: 130, title: '上传时间' }
            , { field: 'FileSize', width: 200, title: '文件大小' }
            , { field: 'FileFormat', width: 100, title: '文件格式' }
            , { title: "操作", fixed: 'right', width: 128, align: 'center', toolbar: '#barDemo' }
        ]]
        , id: 'test'
    });
    table.on('tool(demo)', function (obj) {
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('真的删除吗？', function (index) {
                $.ajax({
                    url: "/FileLIst/DelFile",
                    type: "post",
                    data: data,
                    success: function (result) {
                        $.ajax({
                            url: "/FunctionList/Delete",
                            type: "post",
                            data: data,
                            success: function (result) {
                                if (result.Success) {
                                    layer.msg("刪除成功！", { icon: 1, time: 2000 }, function () { window.location.reload() })
                                } else {
                                    layer.msg("刪除失敗！", { icon: 2, time: 2000 });
                                }
                            }
                        })

                    }
                })
            })
        }
    });
});

$("#GetData").click(function () {
    var table = layui.table;
    var name = $("#name").val();
    var type = $("#type").val();
    table.reload("test", {
        where: {
            FileName: name,
            FileFormat: type
        }
    })
});